﻿using System.Windows;
using MyFloridaHouse.libSvOpenDistricts.Dialogs;
using System;
using MyFloridaHouse.libSvUtilities.Logging;
using MyFloridaHouse.libSvOpenDistricts.enumerations;
using MyFloridaHouse.libSvDTO;
using MyFloridaHouse.libSvOpenDistricts.PDF;

namespace MyFloridaHouse.libSvOpenDistricts.ViewModel
{
    public partial class ViewModelBase
    {

        public BatchPdfDlg batchPdfDlg;

        private bool CmdReportsBatchPDFCanExecute(object parameter)  
        {
            return ((districtPlan.districtCount > 0) & (!isDialogOpen));
        }

        private void CmdReportsBatchPDFExecute(object parameter)
        {
            try
            {
                ReserveDialog(CmdReportsBatchPDF);
                batchPdfDlg = new BatchPdfDlg(OnMemberPropertyChanged, DisplayPanelForDialogs, districtPlan.districtPlanName);
                batchPdfDlg.Start(StartBatchPDFPrint);
            }
            catch (Exception ex)
            {
                Log.NotifyUser("Error starting Batch PDF print : " + ex.Message);
            }
        }

        private void StartBatchPDFPrint(bool result)
        {
            try
            {
                if (result)
                {
                    BatchPDFPrint(batchPdfDlg.title, batchPdfDlg.fileNameRoot.Replace(" ", "_"));
                }
            }
            catch (Exception ex)
            {
                Log.NotifyUser("Unable to continue Batch PDF : " + ex.Message);
            }
            finally
            {
                ReleaseDialog(CmdReportsBatchPDF);
            }
        }

    }
}



